package edu.cuc.socket.url.Socket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerSocketDemo01 {
    public static void main(String[] args) {
        try {
            ServerSocket server = null;
            Socket client = null;
            server = new ServerSocket(8888);
            System.out.println("等待客户端连接");
            client = server.accept();
            String str = "hello world";
            PrintStream out = null;
            out = new PrintStream(client.getOutputStream());
            out.println(str);
            BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
            String readLine = reader.readLine();
            System.out.println(readLine);
            out.close();
            client.close();
            server.close();

        } catch (Exception ex) {
            ex.printStackTrace();
        }


    }
}
